Crate redb

source ·
Expand description

§redb

A simple, portable, high-performance, ACID, embedded key-value store.

redb is written in pure Rust and is loosely inspired by lmdb. Data is stored in a collection of copy-on-write B-trees. For more details, see the design doc.

§Features

  • Zero-copy, thread-safe, BTreeMap based API
  • Fully ACID-compliant transactions
  • MVCC support for concurrent readers & writer, without blocking
  • Crash-safe by default
  • Savepoints and rollbacks

§Example

use redb::{Database, Error, ReadableTable, TableDefinition};

const TABLE: TableDefinition<&str, u64> = TableDefinition::new("my_data");

#[cfg(not(target_os = "wasi"))]
fn main() -> Result<(), Error> {
    let file = tempfile::NamedTempFile::new().unwrap();
    let db = Database::create(file.path())?;
    let write_txn = db.begin_write()?;
    {
        let mut table = write_txn.open_table(TABLE)?;
        table.insert("my_key", &123)?;
    }
    write_txn.commit()?;

    let read_txn = db.begin_read()?;
    let table = read_txn.open_table(TABLE)?;
    assert_eq!(table.get("my_key")?.unwrap().value(), 123);

    Ok(())
}

Modules§

Structs§

Enums§

Traits§